home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / rogue / zap.c < prev   
Encoding:
C/C++ Source or Header  |  1987-05-13  |  4.0 KB  |  204 lines

  1. /*
  2.  * zap.c
  3.  *
  4.  * This source herein may be modified and/or distributed by anybody who
  5.  * so desires, with the following restrictions:
  6.  *    1.)  No portion of this notice shall be removed.
  7.  *    2.)  Credit shall not be taken for the creation of this source.
  8.  *    3.)  This code is not to be traded, sold, or used for personal
  9.  *         gain or profit.
  10.  *
  11.  */
  12.  
  13. #ifndef CURSES
  14. #include <curses.h>
  15. #endif CURSES
  16. #include "rogue.h"
  17.  
  18. boolean wizard = 0;
  19.  
  20. extern boolean being_held, score_only;
  21.  
  22. zapp()
  23. {
  24.     short wch;
  25.     boolean first_miss = 1;
  26.     object *wand;
  27.     short dir, row, col;
  28.     object *monster;
  29.  
  30.     while (!is_direction(dir = rgetchar())) {
  31.         sound_bell();
  32.         if (first_miss) {
  33.             message("direction? ", 0);
  34.             first_miss = 0;
  35.         }
  36.     }
  37.     check_message();
  38.     if (dir == CANCEL) {
  39.         return;
  40.     }
  41.     if ((wch = pack_letter("zap with what?", WAND)) == CANCEL) {
  42.         return;
  43.     }
  44.     check_message();
  45.  
  46.     if (!(wand = get_letter_object(wch))) {
  47.         message("no such item.", 0);
  48.         return;
  49.     }
  50.     if (wand->what_is != WAND) {
  51.         message("you can't zap with that", 0);
  52.         return;
  53.     }
  54.     if (wand->class <= 0) {
  55.         message("nothing happens", 0);
  56.     } else {
  57.         wand->class--;
  58.         row = rogue.row; col = rogue.col;
  59.         monster = get_zapped_monster(dir, &row, &col);
  60.         if (monster) {
  61.             wake_up(monster);
  62.             zap_monster(monster, wand->which_kind);
  63.             relight();
  64.         }
  65.     }
  66.     (void) reg_move();
  67. }
  68.  
  69. object *
  70. get_zapped_monster(dir, row, col)
  71. short dir;
  72. short *row, *col;
  73. {
  74.     short orow, ocol;
  75.  
  76.     for (;;) {
  77.         orow = *row; ocol = *col;
  78.         get_dir_rc(dir, row, col, 0);
  79.         if (((*row == orow) && (*col == ocol)) ||
  80.            (dungeon[*row][*col] & (HORWALL | VERTWALL)) ||
  81.            (dungeon[*row][*col] == NOTHING)) {
  82.             return(0);
  83.         }
  84.         if (dungeon[*row][*col] & MONSTER) {
  85.             if (!imitating(*row, *col)) {
  86.                 return(object_at(&level_monsters, *row, *col));
  87.             }
  88.         }
  89.     }
  90. }
  91.  
  92. zap_monster(monster, kind)
  93. object *monster;
  94. unsigned short kind;
  95. {
  96.     short row, col;
  97.     object *nm;
  98.     short tc;
  99.  
  100.     row = monster->row;
  101.     col = monster->col;
  102.  
  103.     switch(kind) {
  104.     case SLOW_MONSTER:
  105.         if (monster->m_flags & HASTED) {
  106.             monster->m_flags &= (~HASTED);
  107.         } else {
  108.             monster->slowed_toggle = 0;
  109.             monster->m_flags |= SLOWED;
  110.         }
  111.         break;
  112.     case HASTE_MONSTER:
  113.         if (monster->m_flags & SLOWED) {
  114.             monster->m_flags &= (~SLOWED);
  115.         } else {
  116.             monster->m_flags |= HASTED;
  117.         }
  118.         break;
  119.     case TELE_AWAY:
  120.         tele_away(monster);
  121.         break;
  122.     case CONFUSE_MONSTER:
  123.         monster->m_flags |= CONFUSED;
  124.         monster->moves_confused += get_rand(12, 22);
  125.         break;
  126.     case INVISIBILITY:
  127.         monster->m_flags |= INVISIBLE;
  128.         break;
  129.     case POLYMORPH:
  130.         if (monster->m_flags & HOLDS) {
  131.             being_held = 0;
  132.         }
  133.         nm = monster->next_monster;
  134.         tc = monster->trail_char;
  135.         (void) gr_monster(monster, get_rand(0, MONSTERS-1));
  136.         monster->row = row;
  137.         monster->col = col;
  138.         monster->next_monster = nm;
  139.         monster->trail_char = tc;
  140.         if (!(monster->m_flags & IMITATES)) {
  141.             wake_up(monster);
  142.         }
  143.         break;
  144.     case PUT_TO_SLEEP:
  145.         monster->m_flags |= (ASLEEP | NAPPING);
  146.         monster->nap_length = get_rand(3, 6);
  147.         break;
  148.     case MAGIC_MISSILE:
  149.         rogue_hit(monster, 1);
  150.         break;
  151.     case CANCELLATION:
  152.         if (monster->m_flags & HOLDS) {
  153.             being_held = 0;
  154.         }
  155.         if (monster->m_flags & STEALS_ITEM) {
  156.             monster->drop_percent = 0;
  157.         }
  158.         monster->m_flags &= (~(FLIES | FLITS | SPECIAL_HIT | INVISIBLE |
  159.             FLAMES | IMITATES | CONFUSES | SEEKS_GOLD | HOLDS));
  160.         break;
  161.     case DO_NOTHING:
  162.         message("nothing happens", 0);
  163.         break;
  164.     }
  165. }
  166.  
  167. tele_away(monster)
  168. object *monster;
  169. {
  170.     short row, col;
  171.  
  172.     if (monster->m_flags & HOLDS) {
  173.         being_held = 0;
  174.     }
  175.     gr_row_col(&row, &col, (FLOOR | TUNNEL | STAIRS | OBJECT));
  176.     dungeon[monster->row][monster->col] &= ~MONSTER;
  177.  
  178.     monster->row = row; monster->col = col;
  179.     dungeon[row][col] |= MONSTER;
  180.     monster->trail_char = mvinch(row, col);
  181. }
  182.  
  183. wizardize()
  184. {
  185.     char buf[100];
  186.  
  187.     if (wizard) {
  188.         wizard = 0;
  189.         message("not wizard anymore", 0);
  190.     } else {
  191.         if (get_input_line("wizard's password:", "", buf, "", 0, 0)) {
  192.             (void) xxx(1);
  193.             xxxx(buf, strlen(buf));
  194.             if (!strncmp(buf, "\247\104\126\272\115\243\027", 7)) {
  195.                 wizard = 1;
  196.                 score_only = 1;
  197.                 message("Welcome, mighty wizard!", 0);
  198.             } else {
  199.                 message("sorry", 0);
  200.             }
  201.         }
  202.     }
  203. }
  204.